from passlib.context import CryptContext

# 配置密码哈希策略
pwd_context = CryptContext(
    schemes=["pbkdf2_sha256"],  # 使用 PBKDF2 替代 bcrypt
    pbkdf2_sha256__rounds=30000,  # 增加迭代次数提升安全性
    deprecated="auto",
)

def get_password_hash(password: str) -> str:
    """生成密码的哈希值"""
    return pwd_context.hash(password)

def verify_password(plain_password: str, hashed_password: str) -> bool:
    """验证密码是否匹配哈希值"""
    return pwd_context.verify(plain_password, hashed_password)